<?php

namespace app\admin\controller;

use app\admin\model\LeescoreGoods;
use app\common\controller\Backend;
use app\common\model\shop\Goods;
use app\common\model\User;
use app\common\utils\Statistics;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            $time_type = input('time_type/d', 0);
            $create_time = input('time_data/s', '');
            /**
             * 返回参数
             * 'date_type' => '日期类型','style' => '展示格式','length' => '长度','time' => '条件'
             */
            $info = Statistics::get($time_type, $create_time);
            $statistics = Statistics::getDashboard($info['time'], $info['date_type'], $info['style'], $info['length']);
            $rightData = Statistics::rightData($info['time']);

            $this->success('统计信息', null, [
                'statistics' => $statistics,
                'type_zh'    => $info['type_zh'],
                'rightData'  => $rightData
            ]);
        }

        //正式代码区域===============================
        $yewuyuan = User::where(['is_yewuyuan'=>1, 'status'=> 'normal'])->count();
        $totaluser = User::where(['is_yewuyuan'=>0, 'status'=> 'normal'])->count();

        //总种牛数量
        $yuding = Goods::count();
        //礼品总数
        $gift = LeescoreGoods::where(['status'=> ['neq', 0]])->count();
        $this->assign([
            'yewuyuan' => $yewuyuan,
            'totaluser' => $totaluser,
            'yuding' => $yuding,
            'gift' => $gift
        ]);

        return $this->view->fetch();
    }

}
